blob: 8ba3b708b2888dcc2009847305824dec1b5c1ea8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import dbConnect from 'lib/dbConnect'
import withSession from 'lib/withSession'
import Note from 'models/Note'
export default withSession(async (req, res) => {
const { id } = req.query
await dbConnect()
switch (req.method) {
case 'GET':
try {
const user = req.session.get('user')
if (!user || !user?.isVerified || !id ) {
throw new Error('Something went wrong')
}
const note = await Note.findById(id)
if (!note) {
throw new Error('Something went wrong')
}
res.status(200).json(note)
} catch (error) {
res.status(400).json({error: true})
}
break
}
})
|